package com.es.designmode.abstractfactory;

import java.util.UUID;

/**
 * 抽象工厂模式
 * 提供一个创建一系列相关或相互依赖对象的接口，而无需指定他们具体的类
 * 方法 1是抽象工厂
 * 方法 2添加反射，动态配置
 *
 * @author Will
 */
public class ClientSide {

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {

        Department dept = new Department();

        // 1、普通创建
        // 确定实例创建factory
        IFactory factory = new SqlServerFactory();
        //IFactory factory = new OracleFactory();

        IDepartment id = factory.createDepartment();

        id.insert(dept);
        id.getDepartment(UUID.randomUUID().toString());

        // 2、利用反射
        String dbType = "Oracle";
        IFactory reflectFactory = (IFactory) Class.forName("com.es.designmode.abstractfactory." +
                dbType + "Factory").newInstance();

        IDepartment idre = reflectFactory.createDepartment();

        idre.insert(dept);
        idre.getDepartment(UUID.randomUUID().toString());
    }
}
